package org.geekbang.projects.config;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.eclipse.microprofile.config.ConfigValue;
import org.eclipse.microprofile.config.spi.ConfigSource;
import org.eclipse.microprofile.config.spi.Converter;

import java.util.Optional;

/**
* 配置上下文  
* @author : lsq
*/
public class ConfigContext implements Config {


	/**
	 * 获取配置
	 * @return
	 */
	protected Config getConfig(){
		return ConfigProvider.getConfig(Thread.currentThread().getContextClassLoader());
	}


	@Override
	public <T> T getValue(String name, Class<T> aClass) {
		return getConfig().getValue(name , aClass);
	}

	@Override
	public ConfigValue getConfigValue(String name) {
		return getConfig().getConfigValue(name );
	}

	@Override
	public <T> Optional<T> getOptionalValue(String name, Class<T> aClass) {
		return getConfig().getOptionalValue(name , aClass);
	}

	@Override
	public Iterable<String> getPropertyNames() {
		return getConfig().getPropertyNames();
	}

	@Override
	public Iterable<ConfigSource> getConfigSources() {
		return getConfig().getConfigSources();
	}

	@Override
	public <T> Optional<Converter<T>> getConverter(Class<T> aClass) {
		return getConfig().getConverter(aClass);
	}

	@Override
	public <T> T unwrap(Class<T> aClass) {
		return getConfig().unwrap(aClass);
	}
}
